package writer_;

import org.junit.Test;

import java.io.*;

public class FileCopy2 {
    public static void main(String[] s) {

    }

    @Test
    public void copy() throws IOException {
        //读取D:\sucai的str.txt文件写入D:\\xuexi\\str1.txt
        //读取对象
        FileReader fileReader = null;
        //写对象
        FileWriter fileWriter = null;
        //一次读几个字符
        char[] chars = new char[4];
        //读到几个数字
        int charsLen = 0;
        try {
            fileReader = new FileReader("D:\\sucai\\str.txt");
            fileWriter = new FileWriter("D:\\xuexi\\str1.txt");
            while ((charsLen = fileReader.read(chars)) != -1) {
                fileWriter.write(chars);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            fileReader.close();
            fileWriter.close();
        }
    }

}
